package com.migu.spms.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.migu.spms.common.StringUtil;
import com.migu.spms.constant.Constant;
import com.migu.spms.constant.FlowOperateMapping;
import com.migu.spms.dao.entity.BasePage;
import com.migu.spms.dao.entity.ChangeHistoryCriteria;
import com.migu.spms.dao.entity.FunctionRequireCriteria;
import com.migu.spms.dao.entity.FunctionRequireDO;
import com.migu.spms.dao.entity.FunctionRequirementCorrelationRequireCriteria;
import com.migu.spms.dao.entity.FunctionRequirementCorrelationRequireDO;
import com.migu.spms.dao.entity.RequireAttachmentCriteria;
import com.migu.spms.dao.entity.RequireAttachmentDO;
import com.migu.spms.dao.entity.RequireCommentCriteria;
import com.migu.spms.dao.entity.RequireCommentDO;
import com.migu.spms.dao.entity.RequireUserCriteria;
import com.migu.spms.dao.entity.RequireUserDO;
import com.migu.spms.dao.entity.SubParentRequireCriteria;
import com.migu.spms.dao.entity.SubParentRequireDO;
import com.migu.spms.dao.entity.UserInfoDO;
import com.migu.spms.dao.entity.UserProjectCriteria;
import com.migu.spms.dao.entity.UserProjectDO;
import com.migu.spms.dao.inf.IChangeHistoryDO;
import com.migu.spms.dao.inf.IFunctionRequireDO;
import com.migu.spms.dao.inf.IFunctionRequirementCorrelationRequireDO;
import com.migu.spms.dao.inf.IProjectDO;
import com.migu.spms.dao.inf.IRequireAttachmentDO;
import com.migu.spms.dao.inf.IRequireCommentDO;
import com.migu.spms.dao.inf.IRequireTypeTreeDO;
import com.migu.spms.dao.inf.IRequireUserDO;
import com.migu.spms.dao.inf.ISubParentRequireDO;
import com.migu.spms.dao.inf.IUserInfoDO;
import com.migu.spms.dao.inf.IUserProjectDO;
import com.migu.spms.service.data.PaginationResult;
import com.migu.spms.service.data.User;
import com.migu.spms.service.inf.IRequirementService;
import com.migu.spms.utils.InfoTranslateUtil;
import com.migu.spms.utils.PropertiesCopyUtil;
import com.migu.spms.utils.exception.ServiceException;
import com.migu.spms.webapi.data.ButtonInfo;
import com.migu.spms.webapi.data.CommentResponse;
import com.migu.spms.webapi.data.CorrelaRequireResponse;
import com.migu.spms.webapi.data.RequirementDetailInfo;
import com.migu.spms.webapi.data.RequirementDetailsResponse;
import com.migu.spms.webapi.data.RequirementInfo;

/**
 * RequirementServiceImpl类 项目名称: SPMS功能需求 包名称: com.migu.spms.service.impl 类名称:
 * RequirementServiceImpl.java 类描述: 公共服务接口实现 创建人: xs 创建时间: 2017年6月13日 上午9:45
 */
@SuppressWarnings("all")
@Transactional
@Service("requirementServiceImpl")
public class RequirementServiceImpl extends PublicService implements IRequirementService {

	@Resource(name = "IFunctionRequireDO")
	private IFunctionRequireDO functionRequireDAO;

	@Resource(name = "IRequireUserDO")
	private IRequireUserDO requireUserDAO;

	@Resource(name = "IRequireTypeTreeDO")
	private IRequireTypeTreeDO requireTypeTreeDAO;

	@Resource(name = "ISubParentRequireDO")
	private ISubParentRequireDO subParentRequireDAO;

	@Resource(name = "IUserProjectDO")
	private IUserProjectDO userProjuectDAO;

	@Resource(name = "IRequireAttachmentDO")
	private IRequireAttachmentDO requireAttachmentDAO;

	@Resource(name = "IUserInfoDO")
	private IUserInfoDO userInfoDao;

	@Resource(name = "IFunctionRequirementCorrelationRequireDO")
	private IFunctionRequirementCorrelationRequireDO correlaRequireDAO;

	@Resource(name = "IRequireCommentDO")
	private IRequireCommentDO requireCommentDAO;

	@Resource(name = "IChangeHistoryDO")
	private IChangeHistoryDO changeHistoryDAO;

	@Resource(name = "IProjectDO")
	private IProjectDO projectDAO;

	/**
	 * 一次性查出所有需求
	 */
	@Override
	public PaginationResult<RequirementInfo> allRequireByPage(FunctionRequireCriteria functionRequireCriteria,
			User user) throws Exception {
		String requireTypeId = functionRequireCriteria.getRequireTypeId().toString();
		String parameter = parameterIsNotNull(functionRequireCriteria);
		if (parameter.equals("isNull") && requireTypeId.equals(Constant.typeTree.ONE)) {
			// 筛选条件为空、分类为全部需求（显示顶层父需求，且有分层）
			PaginationResult<RequirementInfo> fuzzyKeyIsNull = fuzzyKeyIsNull(functionRequireCriteria, user);
			return fuzzyKeyIsNull;
		} else if (parameter.equals("isNull") && !requireTypeId.equals(Constant.typeTree.ONE)) {
			// 筛选条件为空、有分类（显示顶层父需求，且有分层）
			PaginationResult<RequirementInfo> fuzzyKeyIsNull = fuzzyKeyIsNullTypeNotOne(functionRequireCriteria, user);
			return fuzzyKeyIsNull;
		} else if (parameter.equals("isNotNull")) {
			// 筛选条件不为空
			PaginationResult<RequirementInfo> fuzzyKeyIsNotNull = fuzzyKeyIsNotNull(functionRequireCriteria, user);
			return fuzzyKeyIsNotNull;
		}
		return null;
	}

	/**
	 * 筛选条件的值是否为空
	 */
	private String parameterIsNotNull(FunctionRequireCriteria functionRequireCriteria) {
		String fuzzyKey = functionRequireCriteria.getFuzzyKey();
		String status = functionRequireCriteria.getStatus();
		String priorityRank = functionRequireCriteria.getPriorityRank();
		Long creatorId = functionRequireCriteria.getCreatorId();
		Date createTime = functionRequireCriteria.getCreateTime();
		Long currentHandlerid = functionRequireCriteria.getCurrentHandlerId();
		String actualVersion = functionRequireCriteria.getActualVersion();
		String planOnlineVersion = functionRequireCriteria.getPlanOnlineVersion();
		Date expectFinishTime = functionRequireCriteria.getExpectFinishTime();
		Long developResponsibleId = functionRequireCriteria.getDevelopResponsibleId();
		Long testResponsibleId = functionRequireCriteria.getTestResponsibleId();
		String baselineVersion = functionRequireCriteria.getBaselineVersion();
		// 新增4个时间条件
		Date createStartTime = functionRequireCriteria.getCreateStartTime();
		Date createEndTime = functionRequireCriteria.getCreateEndTime();
		Date expectFinishStartTime = functionRequireCriteria.getExpectFinishStartTime();
		Date expectFinishEndTime = functionRequireCriteria.getExpectFinishEndTime();
		// 版本管理
		String versionManageNum = functionRequireCriteria.getVersionManageNum();
		List<String> filterStatusList = functionRequireCriteria.getFilterStatusList();
		List<String> filterVersionList = functionRequireCriteria.getFilterVersionList();

		if (!StringUtil.isEmpty(fuzzyKey) || !StringUtil.isEmpty(status) || currentHandlerid != null
				|| !StringUtil.isEmpty(actualVersion) || !StringUtil.isEmpty(planOnlineVersion)
				|| !StringUtil.isEmpty(priorityRank) || !StringUtil.isEmpty(baselineVersion) || creatorId != null
				|| developResponsibleId != null || testResponsibleId != null || createTime != null
				|| expectFinishTime != null || createStartTime != null || createEndTime != null
				|| expectFinishStartTime != null || expectFinishEndTime != null || !StringUtil.isEmpty(versionManageNum)
				|| filterStatusList != null || filterVersionList != null) {
			return "isNotNull";
		}
		return "isNull";
	}

	/**
	 * 无条件，无分类
	 */
	private PaginationResult<RequirementInfo> fuzzyKeyIsNull(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		Long projectId = functionRequireCriteria.getProjectId();
		// 当前分类下的所有子分类
		Long pid = functionRequireCriteria.getRequireTypeId();
		if (pid != null) {
			String pid_01 = pid.toString();
			String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
			String[] pidString = typeList.split(",");
			List<Long> pids = new ArrayList<Long>();
			for (String pid_02 : pidString) {
				pids.add(Long.valueOf(pid_02));
			}
			functionRequireCriteria.setRequireTypeId(null);
			functionRequireCriteria.setPids(pids);
		}
		int totalNumber = functionRequireDAO.queryTotalNumberByCriteria(functionRequireCriteria);
		// 给criteria赋值（模糊条件和分页条件，共3个）

		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 自带筛选条件
		// 根据条件查询数据库，得到父需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = functionRequireDAO.queryPage(functionRequireCriteria);
		// 遍历父需求
		for (FunctionRequireDO functionRequire : functionRequireList) {
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);
			// 获取需求主键id
			Long primaryKey = requirementInfo.getId();
			Integer isBaseLine = requirementInfo.getIsBaseLine();
			
			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}

			// 是否有+号
			isPlus(requirementInfo);

			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				// 按钮数组
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					
					Long creatorId = functionRequire.getCreatorId();//创建人才有按钮（开发排期，测试排期，编辑）权限，since 2017-08-16
					//替代下面重复代码
					buildCommonButtonTree(isBaseLine,buttonTree, roleId, userId, creatorId);
//					if (roleId.equals(Constant.Role.DEVELOP_MANAGER) || roleId.equals(Constant.Role.PRODUCT_MANAGER)) {
//						// 项目经理
//						buttonTree.add(Constant.AccessControl.CREATE_SUB_REQUIRE);
//						buttonTree.add(Constant.AccessControl.MOVE_REQUIRE);
//						buttonTree.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
//						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
//						// 未打基线才有按钮（编辑，删除，开发排期，测试排期）
//						if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
//							if(creatorId.equals(userId)){//创建人才有按钮（编辑，删除，开发排期，测试排期）权限，since 2017-08-16								
//								buttonTree.add(Constant.AccessControl.EDITOR);
//								buttonTree.add(Constant.AccessControl.DELETE_REQUIRE);
//								buttonTree.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
//								buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
//							}
//						}
//					} else if (roleId.equals(Constant.Role.TEST_MANAGER)) {
//						// 测试经理
//						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
//						if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
//							if(creatorId.equals(userId)){								
//								buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
//							}
//						}
//					} else {
//						// 其他人员
//						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
//					}
				}
				if (buttonTree.size() > 0) {
					// FlowOperateMapping.sortButtons(buttonTree)
					// String[] buttons = buttonTree.toArray(new
					// String[buttonTree.size()]);
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			// 调用子需求接口
			FunctionRequireCriteria functionRequireCriteria_01 = PropertiesCopyUtil.parse(functionRequire,
					FunctionRequireCriteria.class);
			List<RequirementInfo> requireSubQuery = fuzzyKeyIsNullSubRequire(functionRequireCriteria_01, user);
			if (requireSubQuery != null) {
				requirementInfo.setChildren(requireSubQuery);
			}
			requirementInfoList.add(requirementInfo);
		}
		// 返回10条父需求
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}

	/**
	 * 无条件无分类，返回所有子需求
	 */
	public List<RequirementInfo> fuzzyKeyIsNullSubRequire(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		// 根据主键id去查询是否有子需求id
		Long parentId = functionRequireCriteria.getId();
		Long projectId = functionRequireCriteria.getProjectId();
		
		SubParentRequireCriteria sub = new SubParentRequireCriteria();
		sub.setParentRequireId(parentId);
		List<SubParentRequireDO> subRequireList = subParentRequireDAO.selectByCriteria(sub);
		if (subRequireList != null && subRequireList.size() != 0) {
			List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
			List<FunctionRequireDO> functionRequireDOList = null;

			Long pid = functionRequireCriteria.getRequireTypeId();
			if (pid != null) {
				String pid_01 = pid.toString();
				String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
				String[] pidString = typeList.split(",");
				List<Long> pids = new ArrayList<Long>();
				for (String pid_02 : pidString) {
					pids.add(Long.valueOf(pid_02));
				}
				functionRequireCriteria.setRequireTypeId(null);
				functionRequireCriteria.setPids(pids);
			}
			// 全部需求列表
			functionRequireDOList = functionRequireDAO.selectSubListByCriteria(functionRequireCriteria);

			for (FunctionRequireDO functionRequire : functionRequireDOList) {
				RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);
				// 获取需求主键id
				Long primaryKey = requirementInfo.getId();
				Integer isBaseLine = requirementInfo.getIsBaseLine();

				Long currentHandlerId = functionRequire.getCurrentHandlerId();
				Long userId = (long) user.getUserId();
				// 当前用户为当前处理人时，根据状态status获得操作operate数组
				if (currentHandlerId != null) {
					if (currentHandlerId.equals(userId)) {
						String status = requirementInfo.getStatus();
						if (status != null) {
							String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
							requirementInfo.setOperate(operateByStatus);
						}
					}
				}

				// 是否有+号
				isPlus(requirementInfo);

				// 按钮权限控制
				UserProjectCriteria userInfo = new UserProjectCriteria();
				userInfo.setUid(Integer.valueOf(userId.toString()));
				userInfo.setPid(Integer.valueOf(projectId.toString()));
				List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
				if (userInfoList != null) {
					// 按钮数组
					TreeSet<String> buttonTree = new TreeSet<String>();
					for (UserProjectDO userInfo_01 : userInfoList) {
						Long roleId = Long.valueOf(userInfo_01.getRid().toString());
						// 添加按钮数组
						Long creatorId = functionRequire.getCreatorId();
						buildNoMoveButtonTree(isBaseLine, buttonTree, roleId, userId, creatorId, primaryKey, requirementInfo);
					}
					if (buttonTree.size() > 0) {
						// String[] buttons = buttonTree.toArray(new
						// String[buttonTree.size()]);
						// requirementInfo.setButtons(buttons);
						requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
					}
				}

				// 开发人员
				List<RequireUserCriteria> developers = new ArrayList<>();
				RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
				requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
				requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
				List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
				for (RequireUserDO requireUserDO : developerDOList) {
					RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
					developers.add(developer);
				}
				requirementInfo.setDevelopers(developers);

				// 测试人员
				List<RequireUserCriteria> testers = new ArrayList<>();
				RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
				requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
				requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
				List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
				for (RequireUserDO requireUserDO : testerDOList) {
					RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
					testers.add(tester);
				}
				requirementInfo.setTesters(testers);

				// 调用子需求接口
				FunctionRequireCriteria functionRequireCriteria_01 = PropertiesCopyUtil.parse(functionRequire,
						FunctionRequireCriteria.class);
				List<RequirementInfo> requireSubQuery = fuzzyKeyIsNullSubRequire(functionRequireCriteria_01, user);
				if (requireSubQuery != null) {
					requirementInfo.setChildren(requireSubQuery);
				}
				requirementInfoList.add(requirementInfo);
			}
			return requirementInfoList;
		}
		return null;
	}

	/**
	 * 无条件，有分类
	 */
	private PaginationResult<RequirementInfo> fuzzyKeyIsNullTypeNotOne(FunctionRequireCriteria functionRequireCriteria,
			User user) throws Exception {
		Long projectId = functionRequireCriteria.getProjectId();
		// 当前分类下的所有子分类
		Long pid = functionRequireCriteria.getRequireTypeId();
		if (pid != null) {
			String pid_01 = pid.toString();
			String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
			String[] pidString = typeList.split(",");
			List<Long> pids = new ArrayList<Long>();
			for (String pid_02 : pidString) {
				pids.add(Long.valueOf(pid_02));
			}
			functionRequireCriteria.setPids(pids);
		}
		int totalNumber = functionRequireDAO.fuzzyKeyIsNullTypeNotOneNumber(functionRequireCriteria);

		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 自带筛选条件
		// 根据条件查询数据库，得到父需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = functionRequireDAO
				.fuzzyKeyIsNullTypeNotOne(functionRequireCriteria);
		// 遍历父需求
		for (FunctionRequireDO functionRequire : functionRequireList) {
			// 获取需求主键id
			Long primaryKey = functionRequire.getId();
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);
			Integer isBaseLine = requirementInfo.getIsBaseLine();

			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}

			// 是否有+号
			isPlus(requirementInfo);

			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					Long creatorId = functionRequire.getCreatorId();
					//替代重复代码
					buildCommonButtonTree(isBaseLine,buttonTree, roleId, userId, creatorId);
				}
				if (buttonTree.size() > 0) {
					// String[] buttons = buttonTree.toArray(new
					// String[buttonTree.size()]);
					// requirementInfo.setButtons(buttons);
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			FunctionRequireCriteria functionRequireCriteria_01 = PropertiesCopyUtil.parse(functionRequire,
					FunctionRequireCriteria.class);
			List<RequirementInfo> requireSubQuery = fuzzyKeyIsNullSubRequire(functionRequireCriteria_01, user);
			if (requireSubQuery != null) {
				requirementInfo.setChildren(requireSubQuery);
			}
			requirementInfoList.add(requirementInfo);
		}
		// 返回10条父需求
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}

	/**
	 * 筛选条件不为空
	 */
	private PaginationResult<RequirementInfo> fuzzyKeyIsNotNull(FunctionRequireCriteria functionRequireCriteria,
			User user) throws Exception {
		String fuzzyKey = functionRequireCriteria.getFuzzyKey();
		Long projectId = functionRequireCriteria.getProjectId();
		// 当前分类下的所有子分类
		Long pid = functionRequireCriteria.getRequireTypeId();
		if (pid != null) {
			String pid_01 = pid.toString();
			String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
			String[] pidString = typeList.split(",");
			List<Long> pids = new ArrayList<>();
			for (String pid_02 : pidString) {
				pids.add(Long.valueOf(pid_02));
			}
			functionRequireCriteria.setRequireTypeId(null);
			functionRequireCriteria.setPids(pids);
		}
		int totalNumber = functionRequireDAO.fuzzyKeyIsNotNullNumber(functionRequireCriteria);
		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 自带筛选条件
		// 根据条件查询数据库，得到父需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = functionRequireDAO.fuzzyKeyIsNotNull(functionRequireCriteria);
		// 遍历父需求
		for (FunctionRequireDO functionRequire : functionRequireList) {
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);
			// 获取需求主键id
			Long primaryKey = requirementInfo.getId();
			Integer isBaseLine = requirementInfo.getIsBaseLine();

			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}

			// 是否有+号
			isPlus(requirementInfo);

			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				// 添加按钮数组
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					Long creatorId = functionRequire.getCreatorId();
					buildNoMoveButtonTree(isBaseLine, buttonTree, roleId, userId, creatorId, primaryKey, requirementInfo);
				}
				if (buttonTree.size() > 0) {
					// String[] buttons = buttonTree.toArray(new
					// String[buttonTree.size()]);
					// requirementInfo.setButtons(buttons);
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			requirementInfoList.add(requirementInfo);
		}
		// 返回10条父需求
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}

	/**
	 * 是否是最底层需求
	 */
	private String isNoSubRequire(Long primaryKey, RequirementInfo requirementInfo) {
		String s = "1";
		// 当前需求id,查询父id
		SubParentRequireCriteria requireInfo = new SubParentRequireCriteria();
		requireInfo.setSubRequireId(primaryKey);
		// 子查父
		List<SubParentRequireDO> parentRequireList = subParentRequireDAO.selectByCriteria(requireInfo);
		if (parentRequireList != null && parentRequireList.size() > 0) {
			// 不为空，有父id，得到父id
			for (SubParentRequireDO subRequireDO : parentRequireList) {
				Long parentId = subRequireDO.getParentRequireId();
				SubParentRequireCriteria parentRequire = new SubParentRequireCriteria();
				parentRequire.setSubRequireId(parentId);
				// 父查父父
				List<SubParentRequireDO> grandParentRequireList = subParentRequireDAO.selectByCriteria(parentRequire);
				if (grandParentRequireList != null && grandParentRequireList.size() > 0) {
					for (SubParentRequireDO parentRequireDo : grandParentRequireList) {
						Long grandParentId = parentRequireDo.getParentRequireId();
						SubParentRequireCriteria grandParentRequire = new SubParentRequireCriteria();
						grandParentRequire.setSubRequireId(grandParentId);
						// 父父查父父父
						List<SubParentRequireDO> grandGrandRequireList = subParentRequireDAO
								.selectByCriteria(grandParentRequire);
						if (grandGrandRequireList != null && grandGrandRequireList.size() > 0) {
							// 第四层子需求，无创建子需求按钮
							s = "0";
							return s;
						}
					}
				}
			}
		}
		return s;
	}

	/**
	 * 模糊查询添加条件
	 */
	private void addPageQuery(FunctionRequireCriteria functionRequireCriteria) throws Exception {
		int pageNo = functionRequireCriteria.getPageNo();
		int pageSize = functionRequireCriteria.getPageSize();
		int rowStar = (pageNo - 1) * pageSize;
		int rowEnd = pageNo * pageSize - 1;
		functionRequireCriteria.setRowSrt(rowStar);
		functionRequireCriteria.setRowEnd(rowEnd);
		String fuzzyKey = functionRequireCriteria.getFuzzyKey();
		if (fuzzyKey != null) {
			functionRequireCriteria.setFuzzyKey(fuzzyKey);
		}
	}

	/**
	 * 是否有+号
	 */
	private void isPlus(RequirementInfo requirementInfo) {
		// 是否有+号
		Long primaryKey = requirementInfo.getId();
		SubParentRequireCriteria sub = new SubParentRequireCriteria();
		sub.setParentRequireId(primaryKey);
		List<SubParentRequireDO> subRequireList = subParentRequireDAO.selectByCriteria(sub);
		if (subRequireList != null && subRequireList.size() != 0) {
			// 有子需求，有+号
			requirementInfo.setPlus(true);
		} else {
			// 无子需求，无+号
			requirementInfo.setPlus(false);
		}
	}

	/**
	 * 需求详情
	 */
	@Override
	public RequirementDetailsResponse requireDeatils(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		RequirementDetailsResponse requirementDetailsResponse = new RequirementDetailsResponse();
		Long primaryKey = functionRequireCriteria.getId();
		
		FunctionRequireDO functionRequireInfo = functionRequireDAO.selectByPrimaryKey(primaryKey);
		RequirementDetailInfo requirementDetailInfo = PropertiesCopyUtil.parse(functionRequireInfo,
				RequirementDetailInfo.class);
		Long projectId = requirementDetailInfo.getProjectId();
		String pid=projectId.toString();
		String projectName=projectDAO.selectProjectNameById(pid);
		requirementDetailInfo.setProjectName(projectName);
		// 当前用户为当前处理人时，根据状态status获得操作operate数组
		Long currentHandlerId = requirementDetailInfo.getCurrentHandlerId();
		Long userId = (long) user.getUserId();

		// 当前用户为当前处理人时，根据状态status获得操作operate数组
		if (currentHandlerId != null) {
			if (currentHandlerId.equals(userId)) {
				String status = requirementDetailInfo.getStatus();
				if (status != null) {
					String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
					requirementDetailInfo.setOperate(operateByStatus);
				}
			}
		}

		// 按钮权限控制
		String requireId = requirementDetailInfo.getRequireId();
		// 是否打基线
		Integer isBaseLine = requirementDetailInfo.getIsBaseLine();
		UserProjectCriteria userInfo = new UserProjectCriteria();
		userInfo.setUid(Integer.valueOf(userId.toString()));
		userInfo.setPid(Integer.valueOf(projectId.toString()));
		List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
		Long creatorId = functionRequireInfo.getCreatorId();
		if (userInfoList != null) {
			for (UserProjectDO userInfo_01 : userInfoList) {
				Long roleId = Long.valueOf(userInfo_01.getRid().toString());
				if (roleId.equals(Constant.Role.DEVELOP_MANAGER) || roleId.equals(Constant.Role.PRODUCT_MANAGER)) {
					// 未打基线才有删除按钮
					if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
						if(creatorId.equals(userId)){//创建人才有按钮
							requirementDetailInfo.setEditor(Constant.AccessControl.EDITOR);
						}
						requirementDetailInfo.setUpdateSchedulInfo(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
						requirementDetailInfo.setUpdateTestSchedulInfo(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 更新排期信息（测试）
					}
					requirementDetailInfo.setCopyRequirement(Constant.AccessControl.COPY_REQUIRE);
					requirementDetailInfo.setCorrelationRequirement(Constant.AccessControl.CORRELATION_REQUIRE);
					;
				}else if(roleId.equals(Constant.Role.TEST_MANAGER)){
					if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
						requirementDetailInfo.setUpdateTestSchedulInfo(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 更新排期信息（测试）
					}
				}
			}
		}

		// 附件信息，根据需求id
		RequireAttachmentCriteria requireAttachmentCriteria = new RequireAttachmentCriteria();
		requireAttachmentCriteria.setFunctionRequireId(primaryKey);
		List<RequireAttachmentDO> requireAttachmentDOList = requireAttachmentDAO
				.selectByCriteria(requireAttachmentCriteria);
		List<RequireAttachmentCriteria> requireAttachmentList = new ArrayList<>();
		for (RequireAttachmentDO requireAttachmentDO : requireAttachmentDOList) {
			RequireAttachmentCriteria requireAttachmentCriteria_01 = PropertiesCopyUtil.parse(requireAttachmentDO,
					RequireAttachmentCriteria.class);
			requireAttachmentList.add(requireAttachmentCriteria_01);
		}
		requirementDetailInfo.setRequireAttachmentList(requireAttachmentList);

		// 开发人员
		List<RequireUserCriteria> developers = new ArrayList<>();
		RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
		requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
		requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
		List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
		for (RequireUserDO requireUserDO : developerDOList) {
			RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
			developers.add(developer);
		}
		requirementDetailInfo.setDevelopers(developers);
		// 测试人员
		List<RequireUserCriteria> testers = new ArrayList<>();
		RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
		requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
		requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
		List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
		for (RequireUserDO requireUserDO : testerDOList) {
			RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
			testers.add(tester);
		}
		requirementDetailInfo.setTesters(testers);
		requirementDetailInfo.setProjectName(projectName);
		requirementDetailsResponse.setRequirementDetailInfo(requirementDetailInfo);
		return requirementDetailsResponse;
	}

	/**
	 * 评论接口
	 */
	@Override
	public CommentResponse queryCommentList(FunctionRequireCriteria functionRequireCriteria, User user) {
		CommentResponse commentResponse = new CommentResponse();
		// 查询评论
		Long id = functionRequireCriteria.getId();
		RequireCommentCriteria commentCriteria = new RequireCommentCriteria();
		commentCriteria.setFunctionRequireId(id);
		List<RequireCommentDO> commentDOList = requireCommentDAO.selectRequireCommentList(commentCriteria);
		if (commentDOList != null && commentDOList.size() > 0) {
			List<RequireCommentCriteria> commentList = new ArrayList<>();
			for (RequireCommentDO commentDO : commentDOList) {
				RequireCommentCriteria commentCriteria_01 = PropertiesCopyUtil.parse(commentDO,
						RequireCommentCriteria.class);
				commentList.add(commentCriteria_01);
			}
			commentResponse.setCommentList(commentList);
		}
		return commentResponse;
	}

	/**
	 * 需求详情关联需求分页
	 */
	@Override
	public PaginationResult<RequirementDetailInfo> requireDetailsCorrelation(
			FunctionRequireCriteria functionRequireCriteria, User user) throws Exception {
		// 先根据该需求id查询业务需求id
		Long permaryKey = functionRequireCriteria.getId();
		FunctionRequireDO functionRequireDO_01 = functionRequireDAO.selectByPrimaryKey(permaryKey);
		if (functionRequireDO_01.getRelativeBusinessRequireId() != null
				&& functionRequireDO_01.getRelativeBusinessRequireId() != "") {
			functionRequireCriteria.setRelativeBusinessRequireId(functionRequireDO_01.getRelativeBusinessRequireId());
		}
		Long projectId = functionRequireCriteria.getProjectId();
		String pid=projectId.toString();
		String projectName=projectDAO.selectProjectNameById(pid);
		int totalNumber = functionRequireDAO.queryDetailsNumberByCriteria(functionRequireCriteria);
		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementDetailInfo> requirementDetailInfoList = new ArrayList<RequirementDetailInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 其他条件查询出关联业务需求和功能需求
		List<FunctionRequireDO> FunctionRequireList = functionRequireDAO
				.queryPageByCorrelationRequire(functionRequireCriteria);
		if (FunctionRequireList != null) {
			for (FunctionRequireDO functionRequireDO : FunctionRequireList) {
				String identifi = functionRequireDO.getIdentifi();
				if (identifi.equals("0")) {
					RequirementDetailInfo requirementDetailInfo = PropertiesCopyUtil.parse(functionRequireDO,
							RequirementDetailInfo.class);
					// 后台拼接功能需求跳详情路径
					if (functionRequireDO.getProjectId() != null) {
						Long CorreLationProjectId = functionRequireDO.getProjectId();
						String correLationProjectName = projectDAO
								.selectProjectNameById(CorreLationProjectId.toString());
						StringBuffer sb = new StringBuffer();
						sb.append(CorreLationProjectId).append("/").append(correLationProjectName)
								.append("/functionDetail?id=").append(functionRequireDO.getId()).append("&requireId=")
								.append(functionRequireDO.getRequireId());
						requirementDetailInfo.setJoinString(sb.toString());
						requirementDetailInfoList.add(requirementDetailInfo);
					}
				} else {
					String creatoruid = functionRequireDO.getCreatorName();
					Long uid = Long.valueOf(creatoruid);
					UserInfoDO userInfo = userInfoDao.queryUserInfoByUid(uid);
					String username = userInfo.getUsername();
					functionRequireDO.setCreatorName(username);
					RequirementDetailInfo requirementDetailInfo = PropertiesCopyUtil.parse(functionRequireDO,
							RequirementDetailInfo.class);
					Long id = requirementDetailInfo.getId();
					String requireId = requirementDetailInfo.getRequireId();
					// 拼接
					StringBuffer sb = new StringBuffer();
					//sb.append(projectId.toString()).append("/").append(id.toString()).append("/").append(requireId);
					sb.append("2").append("/").append(id.toString()).append("/").append(requireId);
					requirementDetailInfo.setJoinString(sb.toString());
					requirementDetailInfo.setProjectName(projectName);
					requirementDetailInfoList.add(requirementDetailInfo);
				}
			}

		}

		PaginationResult<RequirementDetailInfo> pageReuslt = new PaginationResult<RequirementDetailInfo>();
		pageReuslt.setRequirementDetailInfoList(requirementDetailInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}

	/**
	 * 关联需求操作，查询需求名
	 */
	@Override
	public CorrelaRequireResponse queryCorrelaRequirementName(FunctionRequireCriteria functionRequireCriteria)
			throws Exception {
		String requireId = functionRequireCriteria.getRequireId();
		if (requireId != null) {
			FunctionRequireDO functionRequireInfo = functionRequireDAO.selectRequireNameByCriteria(requireId);
			CorrelaRequireResponse correlaRequireResponse = new CorrelaRequireResponse();
			if (functionRequireInfo == null) {
				throw new ServiceException("亲，不存在此需求");
			} else {
				FunctionRequireCriteria correlaRequireInfo = PropertiesCopyUtil.parse(functionRequireInfo,
						FunctionRequireCriteria.class);
				correlaRequireResponse.setCorrelaRequireInfo(correlaRequireInfo);
			}
			return correlaRequireResponse;
		}
		return null;
	}

	/**
	 * 关联需求
	 */
	@Override
	public String correlaRequire(FunctionRequireCriteria functionRequireCriteria) throws Exception {
		StringBuffer resultString = new StringBuffer();
		Long id = functionRequireCriteria.getId();
		String requireId = functionRequireCriteria.getRequireId();
		FunctionRequireDO functionRequireInfo = functionRequireDAO.selectRequireNameByCriteria(requireId);
		if (functionRequireInfo == null) {
			throw new ServiceException("亲，不存在此需求");
		} else {
			FunctionRequireCriteria correlaRequireInfo = PropertiesCopyUtil.parse(functionRequireInfo,
					FunctionRequireCriteria.class);
			// 查询出来有该需求，关联需求
			String identifi = correlaRequireInfo.getIdentifi();
			Long id_01 = correlaRequireInfo.getId();
			String requireId_01 = correlaRequireInfo.getRequireId();
			if (identifi.equals("0")) {
				// 功能需求
				FunctionRequirementCorrelationRequireCriteria frcr = new FunctionRequirementCorrelationRequireCriteria();
				frcr.setIdentifi("0");
				frcr.setFunctionRequireId(id.toString());
				frcr.setCorrelationRequireId(id_01.toString());
				FunctionRequirementCorrelationRequireDO frcr_01 = correlaRequireDAO.selectInfoByCriteria(frcr);
				if (frcr_01 == null) {
					int msg = correlaRequireDAO.insertInfoByCriteria(frcr);
					resultString.append(msg);
				} else {
					frcr.setId(frcr_01.getId());
					int msg = correlaRequireDAO.updateInfoByCrtieria(frcr);
					resultString.append(msg);
				}
			} else if (identifi.equals("1")) {
				// 修改主表的业务需求id
				FunctionRequireCriteria func = new FunctionRequireCriteria();
				func.setId(id);
				func.setRelativeBusinessRequireId(requireId);
				functionRequireDAO.updateRelativeRequireId(func);
			}
		}
		return resultString.toString();
	}

	/**
	 * 待我处理和我已处理
	 * 
	 * @throws Exception
	 */
	@Override
	public PaginationResult<RequirementInfo> myCurrent(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		String myCurrent = functionRequireCriteria.getMyCurrent();
		PaginationResult<RequirementInfo> isMyCurrent = null;
		if (myCurrent.equals(Constant.MyCurrent.IS_MY_CURRENT)) {
			// 待我处理
			isMyCurrent = isMyCurrent(functionRequireCriteria, user);
		} else if (myCurrent.equals(Constant.MyCurrent.MY_CURRENTED)) {
			// 我已处理
			isMyCurrent = myCurrented(functionRequireCriteria, user);
		}
		return isMyCurrent;
	}

	// 我已处理
	private PaginationResult<RequirementInfo> myCurrented(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		Long pid = functionRequireCriteria.getRequireTypeId();
		
		if (pid != null) {
			String pid_01 = pid.toString();
			String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
			String[] pidString = typeList.split(",");
			List<Long> pids = new ArrayList<Long>();
			for (String pid_02 : pidString) {
				pids.add(Long.valueOf(pid_02));
			}
			functionRequireCriteria.setPids(pids);
		}
		// 设置当前处理人Id
		functionRequireCriteria.setApprover(Long.valueOf(user.getUserId()));
		int totalNumber = 0;
		if (pid.toString().equals("1")) {
			totalNumber = functionRequireDAO.queryNumberByMyHadCurrentAllRequire(functionRequireCriteria);
		} else {
			totalNumber = functionRequireDAO.queryNumberByMyHadCurrent(functionRequireCriteria);
		}
		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 根据条件查询数据库，得到需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = null;
		if (pid.toString().equals("1")) {
			functionRequireList = functionRequireDAO.queryPageByMyHadCurrentAllRequire(functionRequireCriteria);
		} else {
			functionRequireList = functionRequireDAO.queryPageByMyHadCurrent(functionRequireCriteria);
		}
		for (FunctionRequireDO functionRequire : functionRequireList) {
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);

			// 获取需求主键id
			Long primaryKey = requirementInfo.getId();
			Integer isBaseLine = requirementInfo.getIsBaseLine();
			Long projectId = requirementInfo.getProjectId();

			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}

			// 是否有+号
			isPlus(requirementInfo);

			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				// 添加按钮数组
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					Long creatorId = functionRequire.getCreatorId();
					buildNoMoveButtonTree(isBaseLine, buttonTree, roleId, userId, creatorId, primaryKey, requirementInfo);
				}
				if (buttonTree.size() > 0) {
					// String[] buttons = buttonTree.toArray(new
					// String[buttonTree.size()]);
					// requirementInfo.setButtons(buttons);
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			requirementInfoList.add(requirementInfo);
		}
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
		// changeHistoryDAO
	}

	// 待我处理
	private PaginationResult<RequirementInfo> isMyCurrent(FunctionRequireCriteria functionRequireCriteria, User user)
			throws Exception {
		Long pid = functionRequireCriteria.getRequireTypeId();
		
		if (pid != null) {
			String pid_01 = pid.toString();
			String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
			String[] pidString = typeList.split(",");
			List<Long> pids = new ArrayList<Long>();
			for (String pid_02 : pidString) {
				pids.add(Long.valueOf(pid_02));
			}
			functionRequireCriteria.setPids(pids);
		}
		// 设置当前处理人Id
		functionRequireCriteria.setCurrentHandlerId(Long.valueOf(user.getUserId()));
		int totalNumber = 0;
		if (pid.toString().equals("1")) {
			totalNumber = functionRequireDAO.queryNumberByCurrentAllRequire(functionRequireCriteria);
		} else {
			totalNumber = functionRequireDAO.queryNumberByCurrent(functionRequireCriteria);
		}
		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 根据条件查询数据库，得到需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = null;
		if (pid.toString().equals("1")) {
			functionRequireList = functionRequireDAO.queryPageByCurrentAllRequire(functionRequireCriteria);
		} else {
			functionRequireList = functionRequireDAO.queryPageByCurrent(functionRequireCriteria);
		}
		for (FunctionRequireDO functionRequire : functionRequireList) {
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);

			// 获取需求主键id
			Long primaryKey = requirementInfo.getId();
			Integer isBaseLine = requirementInfo.getIsBaseLine();
			Long projectId = requirementInfo.getProjectId();

			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}

			// 是否有+号
			isPlus(requirementInfo);

			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				// 添加按钮数组
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					Long creatorId = functionRequire.getCreatorId();
					buildNoMoveButtonTree(isBaseLine, buttonTree, roleId, userId, creatorId, primaryKey, requirementInfo);
				}
				if (buttonTree.size() > 0) {
					// String[] buttons = buttonTree.toArray(new
					// String[buttonTree.size()]);
					// requirementInfo.setButtons(buttons);
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			requirementInfoList.add(requirementInfo);
		}
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}

	// 待我处理
	@Override
	public PaginationResult<RequirementInfo> queryHomePageWaitingHandle(FunctionRequireCriteria functionRequireCriteria,
			User user) throws Exception {
		// 设置当前处理人Id
		functionRequireCriteria.setCurrentHandlerId(Long.valueOf(user.getUserId()));
		int totalNumber = 0;
		totalNumber = functionRequireDAO.queryHomePageByWaitingHandleCount(functionRequireCriteria);
		// 给criteria赋值（模糊条件和分页条件，共3个）
		addPageQuery(functionRequireCriteria);
		List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
		BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
		// 根据条件查询数据库，得到需求（分页后的数据量,10条记录）
		List<FunctionRequireDO> functionRequireList = null;
		functionRequireList = functionRequireDAO.queryHomePageByWaitingHandle(functionRequireCriteria);
		for (FunctionRequireDO functionRequire : functionRequireList) {
			RequirementInfo requirementInfo = PropertiesCopyUtil.parse(functionRequire, RequirementInfo.class);
			// 获取需求主键id
			Long primaryKey = requirementInfo.getId();
			Integer isBaseLine = requirementInfo.getIsBaseLine();
			Long projectId = requirementInfo.getProjectId();
            String projectName=projectDAO.selectProjectNameById(projectId.toString());
            requirementInfo.setProjectName(projectName);
			Long currentHandlerId = functionRequire.getCurrentHandlerId();
			Long userId = (long) user.getUserId();
			// 当前用户为当前处理人时，根据状态status获得操作operate数组
			if (currentHandlerId != null) {
				if (currentHandlerId.equals(userId)) {
					String status = requirementInfo.getStatus();
					if (status != null) {
						String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
						requirementInfo.setOperate(operateByStatus);
					}
				}
			}
			// 按钮权限控制
			UserProjectCriteria userInfo = new UserProjectCriteria();
			userInfo.setUid(Integer.valueOf(userId.toString()));
			userInfo.setPid(Integer.valueOf(projectId.toString()));
			List<UserProjectDO> userInfoList = userProjuectDAO.selectListByCriteria(userInfo);
			if (userInfoList != null) {
				// 添加按钮数组
				TreeSet<String> buttonTree = new TreeSet<String>();
				for (UserProjectDO userInfo_01 : userInfoList) {
					Long roleId = Long.valueOf(userInfo_01.getRid().toString());
					if (roleId.equals(Constant.Role.DEVELOP_MANAGER) || roleId.equals(Constant.Role.PRODUCT_MANAGER)) {
						// 项目经理
						// 未打基线才有删除按钮
						if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
							buttonTree.add(Constant.AccessControl.EDITOR);
						}
						// 创建子需求按钮
						String string = isNoSubRequire(primaryKey, requirementInfo);
						if (string.equals("1")) {
							buttonTree.add(Constant.AccessControl.CREATE_SUB_REQUIRE);
						}
						buttonTree.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
						if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
							buttonTree.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
						}
						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
						if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
							buttonTree.add(Constant.AccessControl.DELETE_REQUIRE);
						}
					} else if (roleId.equals(Constant.Role.TEST_MANAGER)) {
						// 测试经理
						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
					} else {
						// 其他人员
						buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
					}
				}
				if (buttonTree.size() > 0) {
					requirementInfo.setButtons(FlowOperateMapping.sortButtons(buttonTree));
				}
			}

			// 开发人员
			List<RequireUserCriteria> developers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
			requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
			List<RequireUserDO> developerDOList = requireUserDAO.selectByCriteria(requireUserCriteria);
			for (RequireUserDO requireUserDO : developerDOList) {
				RequireUserCriteria developer = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				developers.add(developer);
			}
			requirementInfo.setDevelopers(developers);

			// 测试人员
			List<RequireUserCriteria> testers = new ArrayList<>();
			RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
			requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
			requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
			List<RequireUserDO> testerDOList = requireUserDAO.selectByCriteria(requireUserCriteria_01);
			for (RequireUserDO requireUserDO : testerDOList) {
				RequireUserCriteria tester = PropertiesCopyUtil.parse(requireUserDO, RequireUserCriteria.class);
				testers.add(tester);
			}
			requirementInfo.setTesters(testers);

			requirementInfoList.add(requirementInfo);
		}
		PaginationResult<RequirementInfo> pageReuslt = new PaginationResult<RequirementInfo>();
		pageReuslt.setRequiremenInfoList(requirementInfoList);
		pageReuslt.setBasePage(basePage);
		return pageReuslt;
	}
	
	/**
	 * <li>@Description:创建权限按钮树，提取公共代码方便维护
	 * <li>@param buttonTree
	 * <li>@param roleId
	 * <li>@param userId
	 * <li>@param creatorId
	 * <li>创建人：xujiahong
	 * <li>创建时间：2017年8月16日
	 * <li>修改人：
	 * <li>修改时间：
	 */
	private void buildCommonButtonTree(Integer isBaseLine,TreeSet<String> buttonTree,Long roleId,Long userId,Long creatorId){
		if (roleId.equals(Constant.Role.DEVELOP_MANAGER) || roleId.equals(Constant.Role.PRODUCT_MANAGER)) {
			// 项目经理
			buttonTree.add(Constant.AccessControl.CREATE_SUB_REQUIRE);
			buttonTree.add(Constant.AccessControl.MOVE_REQUIRE);
			buttonTree.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
			// 未打基线才有按钮（编辑，删除，开发排期，测试排期）
			if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
				if(creatorId.equals(userId)){//创建人才有按钮（编辑，删除）权限，since 2017-08-16								
					buttonTree.add(Constant.AccessControl.EDITOR);
					buttonTree.add(Constant.AccessControl.DELETE_REQUIRE);
				}
				buttonTree.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
				buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
			}
		} else if (roleId.equals(Constant.Role.TEST_MANAGER)) {
			// 测试经理
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
			if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
				buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
			}
		} else {
			// 其他人员
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
		}
	}
	
	/**
	 * <li>@Description:创建权限按钮树，提取公共代码方便维护
	 * （没有MOVE_REQUIRE按钮，且创建子需求按钮增加判断isNoSubRequire）
	 * <li>@param isBaseLine
	 * <li>@param buttonTree
	 * <li>@param roleId
	 * <li>@param userId
	 * <li>@param creatorId
	 * <li>创建人：xujiahong
	 * <li>创建时间：2017年8月16日
	 * <li>修改人：
	 * <li>修改时间：
	 */
	private void buildNoMoveButtonTree(Integer isBaseLine,TreeSet<String> buttonTree,Long roleId,Long userId,Long creatorId,
			Long primaryKey,RequirementInfo requirementInfo){
		if (roleId.equals(Constant.Role.DEVELOP_MANAGER)|| roleId.equals(Constant.Role.PRODUCT_MANAGER)) {
			// 项目经理
			// 创建子需求按钮
			String string = isNoSubRequire(primaryKey, requirementInfo);
			if (string.equals("1")) {
				buttonTree.add(Constant.AccessControl.CREATE_SUB_REQUIRE);
			}
			buttonTree.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
			
			// 未打基线才有按钮
			if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
				if(creatorId.equals(userId)){//创建人才有按钮（编辑，删除，开发排期，测试排期）权限，since 2017-08-16					
					buttonTree.add(Constant.AccessControl.EDITOR);
					buttonTree.add(Constant.AccessControl.DELETE_REQUIRE);
				}
				buttonTree.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
				buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
			}
		} else if (roleId.equals(Constant.Role.TEST_MANAGER)) {
			// 测试经理
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
			if (isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)) {
				buttonTree.add(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);// 测试排期
			}
		} else {
			// 其他人员
			buttonTree.add(Constant.AccessControl.ADD_COMMENTS);
		}
	}
	

}//class end



// if(identifi.equals("1")){
// //业务需求，先查询关联表，再update
// FunctionRequirementCorrelationRequireCriteria frcr = new
// FunctionRequirementCorrelationRequireCriteria();
// frcr.setIdentifi("1");
// frcr.setFunctionRequireId(id.toString());
// FunctionRequirementCorrelationRequireDO frcr_01 =
// correlaRequireDAO.selectInfoByCriteria(frcr);
// if(frcr_01 == null){
// frcr.setCorrelationRequireId(requireId_01);
// int msg = correlaRequireDAO.insertInfoByCriteria(frcr);
// resultString.append(msg);
// }else{
// frcr.setId(frcr_01.getId());
// frcr.setCorrelationRequireId(requireId_01);
// int msg = correlaRequireDAO.updateInfoByCrtieria(frcr);
// resultString.append(msg);
// }

// /**
// * 分页查询需求列表，也有模糊查询
// * 没有父需求的记录指定数量返回，有父需求的记录，根据父需求id，嵌套
// */
// @Override
// public PaginationResult<RequirementInfo>
// queryRequirementList(FunctionRequireCriteria functionRequireCriteria,User
// user) throws Exception {
// Long projectId = functionRequireCriteria.getProjectId();
// Long pid = functionRequireCriteria.getRequireTypeId();
// if(pid != null){
// String pid_01 = pid.toString();
// String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
// String[] pidString = typeList.split(",");
// List<Long> pids = new ArrayList<>();
// for (String pid_02 : pidString) {
// pids.add(Long.valueOf(pid_02));
// }
// functionRequireCriteria.setRequireTypeId(null);
// functionRequireCriteria.setPids(pids);
// }
// int totalNumber =
// functionRequireDAO.queryTotalNumberByCriteria(functionRequireCriteria);
// //给criteria赋值（模糊条件和分页条件，共3个）
// addPageQuery(functionRequireCriteria);
// List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
// BasePage basePage = this.setBasePage(functionRequireCriteria, totalNumber);
// //自带筛选条件
// //根据条件查询数据库，得到父需求（分页后的数据量,10条记录）
// List<FunctionRequireDO> functionRequireList =
// functionRequireDAO.queryPage(functionRequireCriteria);
// //遍历父需求
// for (FunctionRequireDO functionRequire : functionRequireList) {
// RequirementInfo requirementInfo =
// PropertiesCopyUtil.parse(functionRequire,RequirementInfo.class);
// //根据状态status获得操作operate数组
// String status = requirementInfo.getStatus();
// String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
// requirementInfo.setOperate(operateByStatus);
// //是否有+号
// isPlus(requirementInfo);
// //权限控制
// addUserRoleControl(user,projectId,requirementInfo);
// requirementInfoList.add(requirementInfo);
// }
// //返回10条父需求
// PaginationResult<RequirementInfo> pageReuslt = new
// PaginationResult<RequirementInfo>();
// pageReuslt.setRequiremenInfoList(requirementInfoList);
// pageReuslt.setBasePage(basePage);
// return pageReuslt;
// }
// /**
// * 子需求，点+号，传入requireId、主键id、projectId
// */
// @Override
// public List<RequirementInfo> requireSubQuery(FunctionRequireCriteria
// functionRequireCriteria,User user) throws Exception{
// List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
// //根据主键id去查询是否有子需求id
// Long permaryKey = functionRequireCriteria.getId();
// Long projectId = functionRequireCriteria.getProjectId();
// SubParentRequireCriteria sub = new SubParentRequireCriteria();
// sub.setParentRequireId(permaryKey);
// List<SubParentRequireDO> SubRequireList =
// subParentRequireDAO.selectByCriteria(sub);
// if(SubRequireList != null && SubRequireList.size() != 0){
// //如果有子需求，就查询子需求
// List<FunctionRequireDO> functionRequireDOList = functionRequireDAO.
// selectSubListByCriteria(functionRequireCriteria);
// for (FunctionRequireDO functionRequire : functionRequireDOList) {
// RequirementInfo requirementInfo =
// PropertiesCopyUtil.parse(functionRequire,RequirementInfo.class);
// //根据状态status获得操作operate数组
// String status = requirementInfo.getStatus();
// String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
// requirementInfo.setOperate(operateByStatus);
// //是否有+号
// isPlus(requirementInfo);
// //权限控制
// addUserRoleControl(user,projectId,requirementInfo);
//// requirementInfo.setMoveRequire(null);
// requirementInfoList.add(requirementInfo);
// }
// }
// return requirementInfoList;
// }
// /**
// * 是否显示该需求
// */
// private String isShowThisRequire(Long primaryKey, FunctionRequireDO
// functionRequire,Long pid) {
// String s = "1";
// //当前分类下的所有分类
// String typeList = requireTypeTreeDAO.getTypeTreeList(pid.toString());
// String[] pidString = typeList.split(",");
// for (String pid_02 : pidString) {
// //子查父
// SubParentRequireCriteria requireInfo = new SubParentRequireCriteria();
// requireInfo.setSubRequireId(primaryKey);
// List<SubParentRequireDO> parentRequireList =
// subParentRequireDAO.selectByCriteria(requireInfo);
// if(parentRequireList != null && parentRequireList.size() > 0){
// //不为空，有父id，得到父id
// for (SubParentRequireDO subRequireDO : parentRequireList) {
// Long parentId = subRequireDO.getParentRequireId();
// FunctionRequireDO parentRequireInfo =
// functionRequireDAO.selectByPrimaryKey(parentId);
// //分类相同，不显示
// if(pid_02.equals(parentRequireInfo.getRequireTypeId().toString())){
// return "0";
// }
// //父查父父
// SubParentRequireCriteria parentRequire = new SubParentRequireCriteria();
// parentRequire.setSubRequireId(parentId);
// List<SubParentRequireDO> grandParentRequireList =
// subParentRequireDAO.selectByCriteria(parentRequire);
// if(grandParentRequireList != null && grandParentRequireList.size() > 0){
// for (SubParentRequireDO parentRequireDo : grandParentRequireList) {
// Long grandParentId = parentRequireDo.getParentRequireId();
// FunctionRequireDO grandParentRequireInfo =
// functionRequireDAO.selectByPrimaryKey(grandParentId);
// //分类相同，不显示
// if(pid_02.equals(grandParentRequireInfo.getRequireTypeId().toString())){
// return "0";
// }
// //父父查父父父
// SubParentRequireCriteria grandParentRequire = new SubParentRequireCriteria();
// grandParentRequire.setSubRequireId(grandParentId);
// List<SubParentRequireDO> grandGrandRequireList =
// subParentRequireDAO.selectByCriteria(grandParentRequire);
// if(grandGrandRequireList != null && grandGrandRequireList.size() > 0){
// for (SubParentRequireDO grandGrandRequireDo : grandGrandRequireList) {
// Long grandGrandId = parentRequireDo.getParentRequireId();
// FunctionRequireDO grandGrandRequireInfo =
// functionRequireDAO.selectByPrimaryKey(grandParentId);
// //分类相同，不显示
// if(pid_02.equals(grandGrandRequireInfo.getRequireTypeId().toString())){
// return "0";
// }
// }
// }
// }
// }
// }
// }
// }
// return s;
// }
/// **
// * 无条件，有分类/子需求
// */
// public List<RequirementInfo> requireSubLisrQuery(FunctionRequireCriteria
// functionRequireCriteria,User user) throws Exception{
// //根据主键id去查询是否有子需求id
// Long parentId = functionRequireCriteria.getId();
// Long projectId = functionRequireCriteria.getProjectId();
// SubParentRequireCriteria sub = new SubParentRequireCriteria();
// sub.setParentRequireId(parentId);
// List<SubParentRequireDO> subRequireList =
// subParentRequireDAO.selectSubListByCriteria(sub);
// if(subRequireList != null && subRequireList.size() != 0){
// List<RequirementInfo> requirementInfoList = new ArrayList<RequirementInfo>();
// List<FunctionRequireDO> functionRequireDOList = null;
//
// Long pid = functionRequireCriteria.getRequireTypeId();
// if(pid != null){
// String pid_01 = pid.toString();
// String typeList = requireTypeTreeDAO.getTypeTreeList(pid_01);
// String[] pidString = typeList.split(",");
// List<Long> pids = new ArrayList<Long>();
// for (String pid_02 : pidString) {
// pids.add(Long.valueOf(pid_02));
// }
//// functionRequireCriteria.setRequireTypeId(null);
// functionRequireCriteria.setPids(pids);
// }
//
// //需求分类不为全部需求
// functionRequireDOList =
// functionRequireDAO.selectSubListByParmeter(functionRequireCriteria);
//
// for (FunctionRequireDO functionRequire : functionRequireDOList) {
// RequirementInfo requirementInfo =
// PropertiesCopyUtil.parse(functionRequire,RequirementInfo.class);
// Long primaryKey = functionRequire.getId();
// Integer isBaseLine = requirementInfo.getIsBaseLine();
// Long currentHandlerId = functionRequire.getCurrentHandlerId();
// Long userId = (long) user.getUserId();
// //当前用户为当前处理人时，根据状态status获得操作operate数组
// if(currentHandlerId == userId){
// String status = requirementInfo.getStatus();
// if(status != null){
// String[] operateByStatus = FlowOperateMapping.genFlowOperateByStatus(status);
// requirementInfo.setOperate(operateByStatus);
// }
// }
//
// //是否有+号
// isPlus(requirementInfo);
//
// //权限控制,移动需求为列表特有和创建子需求为前三层需求特有
// UserProjectCriteria userInfo = new UserProjectCriteria();
// userInfo.setUid(Integer.valueOf(userId.toString()));
// userInfo.setPid(Integer.valueOf(projectId.toString()));
// UserProjectDO userInfo_01 = userProjuectDAO.selectByCriteria(userInfo);
// if(userInfo_01 != null){
// Long roleId = Long.valueOf(userInfo_01.getRid().toString());
// //添加按钮数组
// List<String> buttonList = new ArrayList<String>();
// if(roleId == Constant.Role.DEVELOP_MANAGER || roleId ==
// Constant.Role.PRODUCT_MANAGER){
// //项目经理
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// buttonList.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
// buttonList.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
// //未打基线才有删除按钮
// if(isBaseLine.equals(Constant.isBaseLine.UNBASEDLINE)){
// buttonList.add(Constant.AccessControl.EDITOR);
// buttonList.add(Constant.AccessControl.DELETE_REQUIRE);
// }
// //创建子需求按钮
// String string = isNoSubRequire(primaryKey,requirementInfo);
// if(string.equals("1")){
// buttonList.add(Constant.AccessControl.CREATE_SUB_REQUIRE);
// }
// }else if(roleId == Constant.Role.TEST_MANAGER){
// //测试经理
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// }else{
// //其他人员
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// }
// String[] buttons = buttonList.toArray(new String[buttonList.size()]);
// requirementInfo.setButtons(buttons);
// }
//
// //开发人员
// List<RequireUserCriteria> developers = new ArrayList<>();
// RequireUserCriteria requireUserCriteria = new RequireUserCriteria();
// requireUserCriteria.setFunctionRequireId(Long.valueOf(primaryKey));
// requireUserCriteria.setRoleId(Constant.Role.DEVELOPER);
// List<RequireUserDO> developerDOList =
// requireUserDAO.selectByCriteria(requireUserCriteria);
// for (RequireUserDO requireUserDO : developerDOList) {
// RequireUserCriteria developer =
// PropertiesCopyUtil.parse(requireUserDO,RequireUserCriteria.class);
// developers.add(developer);
// }
// requirementInfo.setDevelopers(developers);
//
// //测试人员
// List<RequireUserCriteria> testers = new ArrayList<>();
// RequireUserCriteria requireUserCriteria_01 = new RequireUserCriteria();
// requireUserCriteria_01.setFunctionRequireId(Long.valueOf(primaryKey));
// requireUserCriteria_01.setRoleId(Constant.Role.TESTER);
// List<RequireUserDO> testerDOList =
// requireUserDAO.selectByCriteria(requireUserCriteria_01);
// for (RequireUserDO requireUserDO : testerDOList) {
// RequireUserCriteria tester =
// PropertiesCopyUtil.parse(requireUserDO,RequireUserCriteria.class);
// testers.add(tester);
// }
// requirementInfo.setTesters(testers);
//
// //调用子需求接口
// FunctionRequireCriteria functionRequireCriteria_01 =
// PropertiesCopyUtil.parse(functionRequire,FunctionRequireCriteria.class);
// List<RequirementInfo> requireSubQuery =
// requireSubLisrQuery(functionRequireCriteria_01,user);
// if(requireSubQuery != null){
// requirementInfo.setChildren(requireSubQuery);
// requirementInfoList.add(requirementInfo);
// }
// }
// return requirementInfoList;
// }
// return null;
// }

/// **
// * 是否添加该子需求
// * @param requirementInfoList2
// */
// private void isShowThisSubRequire(Long primaryKey, RequirementInfo
/// requirementInfo, Long pid,FunctionRequireDO functionRequire,User user)
/// throws Exception {
// //当前分类下的所有分类
// String typeList = requireTypeTreeDAO.getTypeTreeList(pid.toString());
// String[] pidString = typeList.split(",");
// for (String pid_02 : pidString) {
//
// //父查子
// SubParentRequireCriteria requireCriteria_01 = new SubParentRequireCriteria();
// requireCriteria_01.setParentRequireId(primaryKey);
// List<SubParentRequireDO> subRequireList =
/// subParentRequireDAO.selectByCriteria(requireCriteria_01);
// if(subRequireList != null && subRequireList.size() > 0){
// //不为空
// for (SubParentRequireDO subRequireDO : subRequireList) {
// List<RequirementInfo> requirementInfoList = new ArrayList<>();
// Long subId = subRequireDO.getSubRequireId();
// FunctionRequireDO subRequireInfo =
/// functionRequireDAO.selectByPrimaryKey(subId);
// if(pid_02.equals(subRequireInfo.getRequireTypeId().toString())){
// //分类相同，添加该子需求
// RequirementInfo requirementInfo_01 =
/// PropertiesCopyUtil.parse(subRequireInfo,RequirementInfo.class);
// requirementInfoList.add(requirementInfo_01);
// //父查孙/分类不相同，有孙查孙，添加为子需求
// SubParentRequireCriteria requireInfo_01 = new SubParentRequireCriteria();
// requireInfo_01.setParentRequireId(subId);
// List<SubParentRequireDO> subRequireList_01 =
/// subParentRequireDAO.selectByCriteria(requireInfo_01);
// //是否调用子需求
// if(subRequireList_01 != null && subRequireList_01.size() > 0){
// isShowThisSubRequire(subId,requirementInfo,pid,subRequireInfo,user);
// }
// }else{
// //父查孙/分类不相同，有孙查孙，添加为子需求
// SubParentRequireCriteria requireInfo_01 = new SubParentRequireCriteria();
// requireInfo_01.setParentRequireId(subId);
// List<SubParentRequireDO> subRequireList_01 =
/// subParentRequireDAO.selectByCriteria(requireInfo_01);
// //是否调用子需求
// if(subRequireList_01 != null && subRequireList_01.size() > 0){
// isShowThisSubRequire(subId,requirementInfo,pid,subRequireInfo,user);
// }
// }
// requirementInfo.setChildren(requirementInfoList);
// }
// }
// }
// }
/// **
// * 权限控制
// */
// private void addUserRoleControl(Long roleId,RequirementInfo requirementInfo)
/// {
// //添加按钮数组
// List<String> buttonList = new ArrayList<String>();
// if(roleId == Constant.Role.DEVELOP_MANAGER || roleId ==
/// Constant.Role.PRODUCT_MANAGER){
// //项目经理
// buttonList.add(Constant.AccessControl.EDITOR);
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// buttonList.add(Constant.AccessControl.DELETE_REQUIRE);
// buttonList.add(Constant.AccessControl.UPDATE_BASELINE_VERSION);
// buttonList.add(Constant.AccessControl.UPDATE_SCHEDUL_INFO);
// }else if(roleId == Constant.Role.TEST_MANAGER){
// //测试经理
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// }else{
// //其他人员
// buttonList.add(Constant.AccessControl.ADD_COMMENTS);
// }
// String[] buttons = buttonList.toArray(new String[buttonList.size()]);
// requirementInfo.setButtons(buttons);
// }